/*
 *  Brno University of Technology
 *
 *  Copyright (C) 2009-2010 by Brno University of Technology and the contributors
 *
 *  Complete list of developers available at our web site:
 *
 *       http://spl.utko.feec.vutbr.cz
 *
 *  This program is free software: you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation, either version 3 of the License, or
 *  (at your option) any later version.
 *
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 *
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this program.  If not, see http://www.gnu.org/licenses/.
 */
package cz.vutbr.feec.utko.ef.ga;

import org.apache.log4j.Logger;

import cz.vutbr.feec.utko.ef.evolution.Chromozome;

/**
 * The Class GAOnePointChromozome is used be genetic algorithm and uses one
 * point crossover.
 */
public class GAOnePointChromozome extends GAUniformChromozome {
	
	/** The log. */
	transient private static Logger log = Logger
			.getLogger(GAOnePointChromozome.class);
	
	/** The Constant serialVersionUID. */
	private static final long serialVersionUID = -5542051614706767816L;

	/**
	 * Instantiates a new gA one point chromozome.
	 * 
	 * @param template the template
	 */
	public GAOnePointChromozome(GAOnePointChromozome template) {
		this.genes.addAll(template.genes);
		// mutate all
		mutateAll();
	}

	/* (non-Javadoc)
	 * @see cz.vutbr.feec.utko.ef.ga.GAUniformChromozome#crossover(cz.vutbr.feec.utko.ef.evolution.Chromozome)
	 */
	@Override
	public void crossover(Chromozome ch) {
		GAOnePointChromozome gao = (GAOnePointChromozome) ch;
		// Crossover point
		// 1 <= random <= ch1.length
		int random = 1 + (int) (Math.random() * (this.genes.size() - 1));

		log.debug("Crossover point = " + random);
		GAGene helper;
		for (int i = random; i < this.genes.size(); i++) {
			helper = this.genes.get(i);
			this.genes.set(i, gao.genes.get(i));
			gao.genes.set(i, helper);
		}
	//	this.evaluateFitness();
	}
}
